<!DOCTYPE html>


<html lang="zn-CH">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="What I can do is to Do My Personal Best!" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    java工具类（excel导入到数据库） |  小熊的博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="http://www.cdn.adingxiong.com/b5363a06dc744d79a94021492bcefe27" />
  
  
<link rel="stylesheet" href="/blog/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/blog/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/blog/atom.xml" title="小熊的博客" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content on">
      <section class="outer">
  <article id="post-文件导入" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  java工具类（excel导入到数据库）
</h1>
 

    </header>
    

    
    <div class="article-meta">
      <a href="/blog/2020/04/18/%E6%96%87%E4%BB%B6%E5%AF%BC%E5%85%A5/" class="article-date">
  <time datetime="2020-04-18T05:47:36.289Z" itemprop="datePublished">2020-04-18</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/blog/categories/%E5%B7%A5%E5%85%B7%E7%B1%BB/">工具类</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">1.3k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">7 min</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    




    

    
    <div class="article-entry" itemprop="articleBody">
      
      

      
      <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">package</span> com.longrise.LGCS.Logic;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.FileInputStream;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.text.DecimalFormat;</span><br><span class="line"><span class="keyword">import</span> java.text.NumberFormat;</span><br><span class="line"><span class="keyword">import</span> java.text.ParseException;</span><br><span class="line"><span class="keyword">import</span> java.text.SimpleDateFormat;</span><br><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.Date;</span><br><span class="line"><span class="keyword">import</span> java.util.List;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> org.apache.poi.hssf.usermodel.HSSFCell;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.hssf.usermodel.HSSFDateUtil;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.hssf.usermodel.HSSFRow;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.hssf.usermodel.HSSFSheet;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.hssf.usermodel.HSSFWorkbook;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.ss.usermodel.FormulaEvaluator;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFCell;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFRow;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFSheet;</span><br><span class="line"><span class="keyword">import</span> org.apache.poi.xssf.usermodel.XSSFWorkbook;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.longrise.LEAP.Base.Logic.LEAPLogic;</span><br><span class="line"><span class="keyword">import</span> com.longrise.LEAP.Base.Service.Resource.NameedPathUtil;</span><br><span class="line"><span class="keyword">import</span> com.longrise.LGCS.Util.PR;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">LGCSReadExcelData</span> <span class="keyword">extends</span> <span class="title">LEAPLogic</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    </span><br><span class="line">String[] FIRSTROWNAME=&#123;<span class="string">"*村（社区）名称"</span>,<span class="string">"*村（居）统一社会信用代码"</span>,<span class="string">"*姓名"</span>,<span class="string">"*类型"</span>,<span class="string">"职务"</span>,<span class="string">"*身份证号"</span>,<span class="string">"*性别"</span>,<span class="string">"*出生年月"</span>,<span class="string">"*政治面貌"</span>,<span class="string">"*学历"</span>,<span class="string">"任期开始时间"</span>,<span class="string">"任期结束时间"</span>&#125;;</span><br><span class="line">    </span><br><span class="line">    <span class="function"><span class="keyword">public</span> PR <span class="title">ReadExamExcelData</span> <span class="params">( String path)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">try</span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span> ( path == <span class="keyword">null</span> || <span class="string">""</span>.equals(path))</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">new</span> PR(<span class="number">0</span>, <span class="string">"读取参数失败!"</span>, <span class="keyword">false</span>);</span><br><span class="line">            path = path.replace(<span class="string">"default/"</span>, NameedPathUtil.getPath(<span class="string">"default"</span>));</span><br><span class="line">            File file = <span class="keyword">new</span> File(path);</span><br><span class="line">            List&lt;List&lt;String&gt;&gt; list = readExcel(file, <span class="number">2</span>, <span class="number">0</span>, <span class="number">11</span>);</span><br><span class="line">            <span class="keyword">if</span>(list==<span class="keyword">null</span> || list.size()==<span class="number">0</span>)</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">new</span> PR(<span class="number">0</span>,<span class="string">"导入模板错误,请点击【模板下载】按钮下载模板!"</span>,<span class="keyword">false</span>);</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> PR(<span class="number">1</span>,<span class="string">"读取excel数据成功!"</span>,list);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span> (IOException e)</span><br><span class="line">        &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> PR(<span class="number">0</span>,e.getMessage(),<span class="keyword">false</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span> (ParseException e)</span><br><span class="line">        &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> PR(<span class="number">0</span>,<span class="string">"时间解析出错"</span>,<span class="keyword">false</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 读取Excel内容</span></span><br><span class="line"><span class="comment">     * </span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> file</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> startRowIndex</span></span><br><span class="line"><span class="comment">     *            起始行下标，从0开始</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> startColumnIndex</span></span><br><span class="line"><span class="comment">     *            起始列下标，从0开始</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> endColumnIndex</span></span><br><span class="line"><span class="comment">     *            结束列下标</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> IOException</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@throws</span> ParseException </span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> List&lt;List&lt;String&gt;&gt; readExcel ( File file , <span class="keyword">int</span> startRowIndex , <span class="keyword">int</span> startColumnIndex , <span class="keyword">int</span> endColumnIndex )<span class="keyword">throws</span> IOException, ParseException</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span> ( file == <span class="keyword">null</span> || !file.isFile() )</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        String fileName = file.getName().toLowerCase();</span><br><span class="line">        <span class="keyword">if</span> ( fileName.endsWith(<span class="string">".xls"</span>) )</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">return</span> read2003Excel(file, startRowIndex, startColumnIndex, endColumnIndex);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> ( fileName.endsWith(<span class="string">".xlsx"</span>) )</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">return</span> read2007Excel(file, startRowIndex, startColumnIndex, endColumnIndex);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> IOException(<span class="string">"不支持的文件类型"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">private</span> List&lt;List&lt;String&gt;&gt; read2003Excel ( File file , <span class="keyword">int</span> startRowIndex , <span class="keyword">int</span> startColumnIndex , <span class="keyword">int</span> endColumnIndex )<span class="keyword">throws</span> IOException, ParseException</span><br><span class="line">    &#123;</span><br><span class="line">        HSSFWorkbook hwb=<span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            List&lt;List&lt;String&gt;&gt; list = <span class="keyword">new</span> ArrayList&lt;List&lt;String&gt;&gt;();</span><br><span class="line">            hwb = <span class="keyword">new</span> HSSFWorkbook(<span class="keyword">new</span> FileInputStream(file));</span><br><span class="line">            HSSFSheet sheet = hwb.getSheetAt(<span class="number">0</span>);</span><br><span class="line">            HSSFRow row = <span class="keyword">null</span>;</span><br><span class="line">            HSSFCell cell = <span class="keyword">null</span>;</span><br><span class="line">            String cellValue = <span class="keyword">null</span>;</span><br><span class="line">            <span class="comment">//判断导入的模板是不是我们的模板,获取第一行作为验证标准 </span></span><br><span class="line">            <span class="keyword">boolean</span> flag=<span class="keyword">true</span>;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt;= endColumnIndex; i++)</span><br><span class="line">            &#123;</span><br><span class="line">                HSSFRow firstRow = sheet.getRow(<span class="number">1</span>);</span><br><span class="line">                HSSFCell firstCell = firstRow.getCell(i);</span><br><span class="line">                <span class="keyword">if</span>(!FIRSTROWNAME[i].equals(firstCell.toString()))&#123;</span><br><span class="line">                    flag=<span class="keyword">false</span>;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span>(flag)&#123;</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = startRowIndex; i &lt;= sheet.getLastRowNum(); i++)</span><br><span class="line">                &#123;   </span><br><span class="line">                    <span class="keyword">int</span> count_blank = <span class="number">0</span>;</span><br><span class="line">                    row = sheet.getRow(i);</span><br><span class="line">                    <span class="keyword">if</span> ( row == <span class="keyword">null</span> )</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="keyword">continue</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                    List&lt;String&gt; rowData = <span class="keyword">new</span> ArrayList&lt;String&gt;();</span><br><span class="line">                    <span class="keyword">for</span> (<span class="keyword">int</span> j = startColumnIndex; j &lt;= endColumnIndex; j++)</span><br><span class="line">                    &#123;</span><br><span class="line">                        cell = row.getCell(j);</span><br><span class="line">                        <span class="keyword">if</span> ( cell == <span class="keyword">null</span> )</span><br><span class="line">                        &#123;</span><br><span class="line">                            count_blank++;</span><br><span class="line">                            rowData.add(<span class="keyword">null</span>);</span><br><span class="line">                            <span class="keyword">continue</span>;</span><br><span class="line">                        &#125;</span><br><span class="line">                        DecimalFormat df = <span class="keyword">new</span> DecimalFormat(<span class="string">"0"</span>);<span class="comment">// 格式化 number String</span></span><br><span class="line">                        <span class="comment">// 字符</span></span><br><span class="line">                        SimpleDateFormat sdf = <span class="keyword">new</span> SimpleDateFormat(<span class="string">"yyyy-MM-dd"</span>);<span class="comment">// 格式化日期字符串</span></span><br><span class="line">                        DecimalFormat nf = <span class="keyword">new</span> DecimalFormat(<span class="string">"0"</span>);<span class="comment">// 格式化数字</span></span><br><span class="line">                        FormulaEvaluator formula = hwb.getCreationHelper().createFormulaEvaluator();</span><br><span class="line">                       </span><br><span class="line">                        <span class="keyword">switch</span> (cell.getCellType())</span><br><span class="line">                        &#123;</span><br><span class="line">                            <span class="keyword">case</span> XSSFCell.CELL_TYPE_STRING:</span><br><span class="line">                                cellValue = cell.getStringCellValue();</span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            <span class="keyword">case</span> XSSFCell.CELL_TYPE_NUMERIC:</span><br><span class="line">                                <span class="keyword">double</span> num = formula.evaluate(cell).getNumberValue();</span><br><span class="line">                                <span class="keyword">if</span>(num == <span class="number">0</span>)&#123;</span><br><span class="line">                                    cellValue = df.format(num);</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span>(num &lt;= <span class="number">100</span> &amp;&amp; num &gt;= <span class="number">0</span>)&#123;</span><br><span class="line">                                    cellValue = nf.format(num);</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span>(<span class="string">"0_ "</span>.equals(cell.getCellStyle().getDataFormatString()) || <span class="string">"0;[Red]0"</span>.equals(cell.getCellStyle().getDataFormatString()))&#123;</span><br><span class="line">                                    cellValue = df.format(cell.getNumericCellValue());</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span> ( <span class="string">"@"</span>.equals(cell.getCellStyle().getDataFormatString()) )</span><br><span class="line">                                &#123;</span><br><span class="line">                                    cellValue = df.format(cell.getNumericCellValue());</span><br><span class="line">                </span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span> ( <span class="string">"General"</span>.equals(cell.getCellStyle().getDataFormatString()) )</span><br><span class="line">                                &#123;</span><br><span class="line">                                    cellValue = nf.format(cell.getNumericCellValue());</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span></span><br><span class="line">                                &#123;</span><br><span class="line">                                    cellValue = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            <span class="keyword">case</span> XSSFCell.CELL_TYPE_BLANK:</span><br><span class="line">                                cellValue = <span class="string">""</span>;</span><br><span class="line">                                count_blank++;</span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            <span class="keyword">case</span>  XSSFCell.CELL_TYPE_FORMULA:</span><br><span class="line">                                String str = <span class="string">""</span>;</span><br><span class="line">                                str = formula.evaluate(cell).getStringValue();</span><br><span class="line">                                cellValue = str;</span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            <span class="keyword">default</span>:</span><br><span class="line">                                cellValue = cell.toString();</span><br><span class="line">                        &#125;</span><br><span class="line">                        cellValue = cellValue.replaceAll(<span class="string">"\\s*"</span>,<span class="string">""</span>);</span><br><span class="line">                        cellValue = cellValue.replace(<span class="string">" "</span>, <span class="string">""</span>);</span><br><span class="line"><span class="comment">//                        cellValue = cellValue.replaceAll("&lt;","&amp;lt;");</span></span><br><span class="line"><span class="comment">//                        cellValue = cellValue.replaceAll("&gt;","&amp;gt;");</span></span><br><span class="line">                        rowData.add(cellValue);</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">if</span>(count_blank!=endColumnIndex+<span class="number">1</span>)&#123;</span><br><span class="line">                        list.add(rowData);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> list;</span><br><span class="line">        &#125;<span class="keyword">catch</span>(IOException e)&#123;</span><br><span class="line">            <span class="keyword">throw</span> e;</span><br><span class="line">        &#125;<span class="keyword">finally</span>&#123;</span><br><span class="line">            <span class="keyword">try</span>&#123;</span><br><span class="line">                <span class="keyword">if</span>(hwb!=<span class="keyword">null</span>)&#123;</span><br><span class="line">                    hwb.close();</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span>(file!=<span class="keyword">null</span> &amp;&amp; file.exists() &amp;&amp; file.isFile())&#123;</span><br><span class="line">                    file.delete();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;<span class="keyword">catch</span>(IOException e)&#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> List&lt;List&lt;String&gt;&gt; read2007Excel ( File file , <span class="keyword">int</span> startRowIndex , <span class="keyword">int</span> startColumnIndex , <span class="keyword">int</span> endColumnIndex )<span class="keyword">throws</span> IOException, ParseException</span><br><span class="line">    &#123;</span><br><span class="line">        XSSFWorkbook xwb=<span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            List&lt;List&lt;String&gt;&gt; list = <span class="keyword">new</span> ArrayList&lt;List&lt;String&gt;&gt;();</span><br><span class="line">            xwb = <span class="keyword">new</span> XSSFWorkbook(<span class="keyword">new</span> FileInputStream(file));</span><br><span class="line">            <span class="comment">// 读取第一章表格内容</span></span><br><span class="line">            XSSFSheet sheet = xwb.getSheetAt(<span class="number">0</span>);</span><br><span class="line">            XSSFRow row = <span class="keyword">null</span>;</span><br><span class="line">            XSSFCell cell = <span class="keyword">null</span>;</span><br><span class="line">            String cellValue = <span class="keyword">null</span>;</span><br><span class="line">            <span class="comment">//判断导入的模板是不是我们的模板,获取第一行作为验证标准</span></span><br><span class="line">            <span class="keyword">boolean</span> flag=<span class="keyword">true</span>;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt;= endColumnIndex; i++)</span><br><span class="line">            &#123;</span><br><span class="line">                XSSFRow firstRow = sheet.getRow(<span class="number">1</span>);</span><br><span class="line">                XSSFCell firstCell = firstRow.getCell(i);</span><br><span class="line">                <span class="keyword">if</span>(!FIRSTROWNAME[i].equals(firstCell.toString()))&#123;</span><br><span class="line">                    flag=<span class="keyword">false</span>;</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            </span><br><span class="line">            <span class="keyword">if</span>(flag)&#123;</span><br><span class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = startRowIndex; i &lt;= sheet.getLastRowNum(); i++)</span><br><span class="line">                &#123;</span><br><span class="line">                    <span class="keyword">int</span> count_blank = <span class="number">0</span>;</span><br><span class="line">                    row = sheet.getRow(i);</span><br><span class="line">                    <span class="keyword">if</span> ( row == <span class="keyword">null</span> )</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="keyword">continue</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                    List&lt;String&gt; rowData = <span class="keyword">new</span> ArrayList&lt;String&gt;();</span><br><span class="line">                    <span class="keyword">for</span> (<span class="keyword">int</span> j = startColumnIndex; j &lt;= endColumnIndex; j++)</span><br><span class="line">                    &#123;</span><br><span class="line">                        <span class="comment">// for (int j = row.getFirstCellNum(); j &lt; row.getLastCellNum();</span></span><br><span class="line">                        <span class="comment">// j++) &#123;</span></span><br><span class="line">                        cell = row.getCell(j);</span><br><span class="line">                        <span class="keyword">if</span> ( cell == <span class="keyword">null</span> )</span><br><span class="line">                        &#123;</span><br><span class="line">                            count_blank++;</span><br><span class="line">                            rowData.add(<span class="keyword">null</span>);</span><br><span class="line">                            <span class="keyword">continue</span>;</span><br><span class="line">                        &#125;</span><br><span class="line">                        DecimalFormat df = <span class="keyword">new</span> DecimalFormat(<span class="string">"0"</span>);<span class="comment">// 格式化 number String</span></span><br><span class="line">                        <span class="comment">// 字符</span></span><br><span class="line">                        SimpleDateFormat sdf = <span class="keyword">new</span> SimpleDateFormat(<span class="string">"yyyy-MM-dd"</span>);<span class="comment">// 格式化日期字符串</span></span><br><span class="line">                        DecimalFormat nf = <span class="keyword">new</span> DecimalFormat(<span class="string">"0"</span>);<span class="comment">// 格式化数字</span></span><br><span class="line">                        FormulaEvaluator formula = xwb.getCreationHelper().createFormulaEvaluator();</span><br><span class="line">                        <span class="keyword">switch</span> (cell.getCellType())</span><br><span class="line">                        &#123;</span><br><span class="line">                            <span class="keyword">case</span> XSSFCell.CELL_TYPE_STRING:</span><br><span class="line">                                cellValue = cell.getStringCellValue();</span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            <span class="keyword">case</span> XSSFCell.CELL_TYPE_NUMERIC:</span><br><span class="line">                                <span class="keyword">double</span> num = formula.evaluate(cell).getNumberValue();</span><br><span class="line">                                <span class="keyword">if</span>(num == <span class="number">0</span>)&#123;</span><br><span class="line">                                    cellValue = df.format(num);</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span>(num &lt;= <span class="number">100</span> &amp;&amp; num &gt;= <span class="number">0</span>)&#123;</span><br><span class="line">                                    cellValue = nf.format(num);</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span>(<span class="string">"0_ "</span>.equals(cell.getCellStyle().getDataFormatString()) || <span class="string">"0;[Red]0"</span>.equals(cell.getCellStyle().getDataFormatString()))&#123;</span><br><span class="line">                                    cellValue = df.format(cell.getNumericCellValue());</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span> ( <span class="string">"@"</span>.equals(cell.getCellStyle().getDataFormatString()) )</span><br><span class="line">                                &#123;</span><br><span class="line">                                    cellValue = df.format(cell.getNumericCellValue());</span><br><span class="line">                </span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span> <span class="keyword">if</span> ( <span class="string">"General"</span>.equals(cell.getCellStyle().getDataFormatString()) )</span><br><span class="line">                                &#123;</span><br><span class="line">                                    cellValue = nf.format(cell.getNumericCellValue());</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">else</span></span><br><span class="line">                                &#123;</span><br><span class="line">                                    cellValue = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));</span><br><span class="line">                                &#125;</span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            <span class="keyword">case</span> XSSFCell.CELL_TYPE_BLANK:</span><br><span class="line">                                cellValue = <span class="string">""</span>;</span><br><span class="line">                                count_blank ++;</span><br><span class="line">                                <span class="keyword">break</span>;</span><br><span class="line">                            <span class="keyword">case</span>  XSSFCell.CELL_TYPE_FORMULA:</span><br><span class="line">                                String str = <span class="string">""</span>;</span><br><span class="line">                                str = formula.evaluate(cell).getStringValue();</span><br><span class="line">                                cellValue = str;</span><br><span class="line">                                <span class="keyword">break</span>;   </span><br><span class="line">                            <span class="keyword">default</span>:</span><br><span class="line">                                cellValue = cell.toString();</span><br><span class="line">                        &#125;</span><br><span class="line">                        cellValue = cellValue.replaceAll(<span class="string">"\\s*"</span>,<span class="string">""</span>);</span><br><span class="line">                        cellValue = cellValue.replace(<span class="string">" "</span>, <span class="string">""</span>);</span><br><span class="line"><span class="comment">//                        cellValue = cellValue.replaceAll("&lt;","&amp;lt;");</span></span><br><span class="line"><span class="comment">//                        cellValue = cellValue.replaceAll("&gt;","&amp;gt;");</span></span><br><span class="line">                        rowData.add(cellValue);</span><br><span class="line">                    &#125;</span><br><span class="line">                    <span class="keyword">if</span>(count_blank!=endColumnIndex+<span class="number">1</span>)&#123;</span><br><span class="line">                        list.add(rowData);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> list;</span><br><span class="line">        &#125;<span class="keyword">catch</span>(IOException e)&#123;</span><br><span class="line">            <span class="keyword">throw</span> e;</span><br><span class="line">        &#125;<span class="keyword">finally</span>&#123;</span><br><span class="line">            <span class="keyword">try</span>&#123;</span><br><span class="line">                <span class="keyword">if</span>(xwb!=<span class="keyword">null</span>)&#123;</span><br><span class="line">                    xwb.close();</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span>(file!=<span class="keyword">null</span> &amp;&amp; file.exists() &amp;&amp; file.isFile())&#123;</span><br><span class="line">                    file.delete();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;<span class="keyword">catch</span>(IOException e)&#123;</span><br><span class="line">                e.printStackTrace();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>







      
      <!-- reward -->
      
      <div id="reward-btn">
        Donate
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>Copyright： </strong>
              Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://bodboy.gitee.io/blog/2020/04/18/%E6%96%87%E4%BB%B6%E5%AF%BC%E5%85%A5/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/excel/" rel="tag">excel</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/java/" rel="tag">java</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/blog/2020/04/18/%E7%BB%84%E4%BB%B6%E4%B9%8B%E5%89%8D%E7%9A%84%E9%80%9A%E8%AE%AF/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            vue的组件通讯
          
        </div>
      </a>
    
    
      <a href="/blog/2020/04/18/%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83%20/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">微服务注册中心</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'uW8QYGvvhWmNWdiwpznJ0GVa-gzGzoHsz',
        app_key: 'LrJhMzx9qEwcMV1DJjTI6f6C',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: '[object Object]',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2021
        <i class="ri-heart-fill heart_icon"></i> panda
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/blog/"><img src="https://portrait.gitee.com/uploads/avatars/user/1007/3023420_bodboy_1578973210.png!avatar200" alt="小熊的博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags/%E6%97%85%E8%A1%8C/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/blog/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/blog/js/jquery-2.0.3.min.js"></script>


<script src="/blog/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/blog/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/blog/dist/main.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>




<script src="/blog/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

  
<script src="/blog/js/clickLove.js"></script>



<!-- 复制 -->



    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=1297802566&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
  </div>
</body>

</html>